﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Data.OleDb;

namespace covua
{
    public partial class Form2 : Form
    {
        Point toadodi = new Point();
        Point toadoden = new Point();
        int chon=1;
        public DATABASECONNECT DaTa = new DATABASECONNECT();
        public TAIKHOAN TaiKhoan = new TAIKHOAN();

        string ten1;
        string ten2;
        string pass1;
        string pass2;

        public Form2(string t1,string p1,string t2,string p2)
        {
            InitializeComponent();

            ten1 = t1;
            ten2 = t2;
            pass1 = p1;
            pass2 = p2;

            DaTa.CreateConnect();
            if(ten1!="")
                ngchoi1.Text = "Người chơi 1: "+ten1+" Xin Thua ";

            if (ten2 != "")
                ngchoi2.Text = "Người chơi 2: "+ten2 + " Xin Thua ";

            huongdan.Text = "Cách chơi: ";
            hd.Text = "Người chơi 1 Cờ đỏ";
            hd5.Text = "Người chơi 2 Cờ trắng";
            hd1.Text = "Chọn quân cờ cần đi";
            hd2.Text = " Chọn nơi cần đến.";
            hd3.Text = "Nếu quân cờ chưa được đánh.";
            hd4.Text = "Chọn lại quân cờ cần đi.";
            ten_luu.Text = "Tên Lưu :";
            file_luu.Hide();
            ten_luu.Hide();
            luu_file.Hide();

            pb1.Hide();
            pb2.Hide();
            pb3.Hide();
            pb4.Hide();

            mo.Hide();
            AnCo();
            NewGame();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
           

        }

        private void button2_Click(object sender, EventArgs e)
        {
            // an co trang:

            

            ///

            /*
            wvua1.Hide();
            //wvua2.Hide();

            //whau1.Hide();
            whau2.Hide();

            // wtuong1.Hide();
            // wtuong2.Hide();

            //wxe11.Hide();
            wxe12.Hide();
            wxe21.Hide();
            //wxe22.Hide();

            //wma11.Hide();
            wma12.Hide();
            wma21.Hide();
            // wma22.Hide();


            // wchot11.Hide();
            wchot12.Hide();
            wchot21.Hide();
            //  wchot22.Hide();
            //  wchot31.Hide();
            wchot32.Hide();
            wchot41.Hide();
            //  wchot42.Hide();
            //  wchot51.Hide();
            wchot52.Hide();
            wchot61.Hide();
            // wchot62.Hide();
            //  wchot71.Hide();
            wchot72.Hide();
            wchot81.Hide();
            //  wchot82.Hide();
            ///
            /// an co den:

            //bvua1.Hide();
            bvua2.Hide();

            bhau1.Hide();
            //bhau2.Hide();

            // btuong1.Hide();
            // btuong2.Hide();

            bxe11.Hide();
            //  bxe12.Hide();
            // bxe21.Hide();
            bxe22.Hide();

            // bma11.Hide();
            bma12.Hide();
            bma21.Hide();
            // bma22.Hide();


            // bchot11.Hide();
            bchot12.Hide();
            bchot21.Hide();
            // bchot22.Hide();
            // bchot31.Hide();
            bchot32.Hide();
            bchot41.Hide();
            // bchot42.Hide();
            // bchot51.Hide();
            bchot52.Hide();
            bchot61.Hide();
            // bchot62.Hide();
            // bchot71.Hide();
            bchot72.Hide();
            bchot81.Hide();
            // bchot82.Hide();
            */
            
            /////
           // ChessBoard();

//            CapNhat();
            AnCo();
            NewGame();

          

          

        }
        private void AnCo()
        {

            pb1.Hide();
            pb2.Hide();
            pb3.Hide();
            pb4.Hide();

            
            wvua1.Hide();
            wvua2.Hide();

            whau1.Hide();
            whau2.Hide();
            whau3.Hide();
            whau4.Hide();
            whau5.Hide();
            whau6.Hide();

            wtuong1.Hide();
            wtuong2.Hide();

            wxe11.Hide();
            wxe12.Hide();
            wxe21.Hide();
            wxe22.Hide();

            wma11.Hide();
            wma12.Hide();
            wma21.Hide();
            wma22.Hide();


            wchot11.Hide();
            wchot12.Hide();
            wchot21.Hide();
            wchot22.Hide();
            wchot31.Hide();
            wchot32.Hide();
            wchot41.Hide();
            wchot42.Hide();
            wchot51.Hide();
            wchot52.Hide();
            wchot61.Hide();
            wchot62.Hide();
            wchot71.Hide();
            wchot72.Hide();
            wchot81.Hide();
            wchot82.Hide();
            ///
            /// an co den:

            bvua1.Hide();
            bvua2.Hide();

            bhau1.Hide();
            bhau2.Hide();
            bhau3.Hide();
            bhau4.Hide();
            bhau5.Hide();
            bhau6.Hide();

            btuong1.Hide();
            btuong2.Hide();

            bxe11.Hide();
            bxe12.Hide();
            bxe21.Hide();
            bxe22.Hide();

            bma11.Hide();
            bma12.Hide();
            bma21.Hide();
            bma22.Hide();


            bchot11.Hide();
            bchot12.Hide();
            bchot21.Hide();
            bchot22.Hide();
            bchot31.Hide();
            bchot32.Hide();
            bchot41.Hide();
            bchot42.Hide();
            bchot51.Hide();
            bchot52.Hide();
            bchot61.Hide();
            bchot62.Hide();
            bchot71.Hide();
            bchot72.Hide();
            bchot81.Hide();
            bchot82.Hide();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox1.Location.X;
            temp.Y = pictureBox1.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);
           
            DanhCo();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox2.Location.X;
            temp.Y = pictureBox2.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            DanhCo();
        }
    

    /*{
        static void Main(string[] args)
        {
            ChessBoard board= new ChessBoard();
            short t;
            board.Print();
            do
            {
                Console.Write("\nNguoi choi 1:");
                t = board.Move(1);
                board.Print();
                if (t != 0)
                    break;
                Console.Write("\nNguoi choi 2:");
                t = board.Move(2);
                board.Print();
            }while(t==0);
            if (t == 1)
                Console.WriteLine("NGUOI CHOI THU 1 LA NGUOI CHIEN THANG!");
            else
                Console.Write("NGUOI CHOI THU 2 LA NGUOI CHIEN THANG!");
            
                
            
            Console.ReadKey();
        }
    }*/
   /* public class ChessBoard
    {*/

        public void NewGame()
        {
            pb1.Hide();
            pb2.Hide();
            pb3.Hide();
            pb4.Hide();

            file_luu.Hide();
            ten_luu.Hide();
            luu_file.Hide();
            mo.Hide();
            ChessBoard();
            CapNhat();
           // tb1.Text = "nguoi choi 1 danh";
           // tb1.Show();
           // if (chon == 2)
             //   DanhCo();
            //short t;
            //t = Move(1);

         /*   do
            {
                t = Move(1);
                if (t != 0)
                    break;
                t = Move(2);
            } while (t == 0);*/
            // t= 1  nguoi choi 1 chien thang;
            // t =2 nguoi choi 2 chien thang;
        
        }


        public void ChessBoard()
        {
            short i, j;
            // khoi tao quan co cho nguoi choi 1
            i = 1;
            for (j = 0; j < 8; j++)
                chess[i, j] = new Chessman(i, j, 1, 1);
            i = 0;
            for (j = 0; j < 5; j++)
                chess[i, j] = new Chessman(i, j, (short)(j + 2), 1);
            chess[0, 5] = new Chessman(0, 5, 4, 1);
            chess[0, 6] = new Chessman(0, 6, 3, 1);
            chess[0, 7] = new Chessman(0, 7, 2, 1);
            // khoi tao quan co cho nguoi choi 2
            i = 6;
            for (j = 0; j < 8; j++)
                chess[i, j] = new Chessman(i, j, 1, 2);
            i = 7;
            for (j = 0; j < 5; j++)
                chess[i, j] = new Chessman(i, j, (short)(j + 2), 2);
            chess[7, 5] = new Chessman(7, 5, 4, 2);
            chess[7, 6] = new Chessman(7, 6, 3, 2);
            chess[7, 7] = new Chessman(7, 7, 2, 2);
            // nhung khoi tao con lai
            i = 2;
            while (i <= 5)
            {
                for (j = 0; j < 8; j++)
                    chess[i, j] = new Chessman(i, j);
                i++;
            }
        }
        // xuat man hinh
          public void CapNhat()
          {
             // Console.WriteLine("\n\n");
              AnCo();
              short i, j;
              int chot1 = 0; int tuong1 = 0; int hau1 = 0; int vua1 = 0; int xe1 = 0; int ma1 = 0;
              int chot2 = 0; int tuong2 = 0; int hau2 = 0; int vua2 = 0; int xe2 = 0; int ma2 = 0;
              for (i = 0; i < 8; i++)
              {
                  for (j = 0; j < 8; j++)
                  {
                      if (chess[i, j].Player == 1)
                      {
                          
                           // chuyen toa do code wa toa do man hinh
                          Point temp = new Point();
                          temp.X = (j * 90) + 10;
                          temp.Y = (i * 90) + 10;


                          switch (chess[i, j].Type)
                          {
                              case 1:
                                  {
                                      chot1 = (chot1+1);
                                      switch (chot1)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot11.Location = temp;
                                                  bchot11.Show();
                                              }
                                              else
                                              {
                                                  bchot12.Location = temp;
                                                  bchot12.Show();
                                              }
                                              break;
                                        /////
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot21.Location = temp;
                                                  bchot21.Show();
                                              }
                                              else
                                              {
                                                  bchot22.Location = temp;
                                                  bchot22.Show();
                                              }
                                       
                                              break;
                                       ////
                                          case 3:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot31.Location = temp;
                                                  bchot31.Show();
                                              }
                                              else
                                              {
                                                  bchot32.Location = temp;
                                                  bchot32.Show();
                                              }
                                              break;
                                       ////
                                              case 4:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot41.Location = temp;
                                                  bchot41.Show();
                                              }
                                              else
                                              {
                                                  bchot42.Location = temp;
                                                  bchot42.Show();
                                              }
                                       
                                              break;
                                       ////
                                              case 5:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot51.Location = temp;
                                                  bchot51.Show();
                                              }
                                              else
                                              {
                                                  bchot52.Location = temp;
                                                  bchot52.Show();
                                              }

                                              break;
                                          ////
                                              case 6:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot61.Location = temp;
                                                  bchot61.Show();
                                              }
                                              else
                                              {
                                                  bchot62.Location = temp;
                                                  bchot62.Show();
                                              }

                                              break;
                                          ////
                                              case 7:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot71.Location = temp;
                                                  bchot71.Show();
                                              }
                                              else
                                              {
                                                  bchot72.Location = temp;
                                                  bchot72.Show();
                                              }

                                              break;
                                          ////
                                              case 8:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bchot81.Location = temp;
                                                  bchot81.Show();
                                              }
                                              else
                                              {
                                                  bchot82.Location = temp;
                                                  bchot82.Show();
                                              }

                                              break;
                                          ////
                                      }
                                  }
                                  break;
                              case 2:
                                  {
                                      xe1 = xe1 + 1;
                                      switch (xe1)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bxe11.Location = temp;
                                                  bxe11.Show();
                                              }
                                              else
                                              {
                                                  bxe12.Location = temp;
                                                  bxe12.Show();
                                              }
                                              break;
                                              ///
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bxe21.Location = temp;
                                                  bxe21.Show();
                                              }
                                              else
                                              {
                                                  bxe22.Location = temp;
                                                  bxe22.Show();
                                              }
                                              break;
                                      }
                                  }
                                  break;

                                  //
                              case 3:
                                  {
                                      ma1 = ma1 + 1;
                                      switch (ma1)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bma11.Location = temp;
                                                  bma11.Show();
                                              }
                                              else
                                              {
                                                  bma12.Location = temp;
                                                  bma12.Show();
                                              }
                                              break;
                                          ///
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  bma21.Location = temp;
                                                  bma21.Show();
                                              }
                                              else
                                              {
                                                  bma22.Location = temp;
                                                  bma22.Show();
                                              }
                                              break;
                                      }
                                  }
                                  break;

                              case 4:
                                  {
                                      
                                      if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                      {
                                          btuong2.Location = temp;
                                          btuong2.Show();
                                      }
                                      else
                                      {
                                          btuong1.Location = temp;
                                          btuong1.Show();
                                      }
                                  }
                                  break;

                              case 5:
                                  {
                                      hau1 = hau1 + 1;
                                      switch (hau1)
                                      {
                                          case 1:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      bhau1.Location = temp;
                                                      bhau1.Show();
                                                  }
                                                  else
                                                  {
                                                      bhau2.Location = temp;
                                                      bhau2.Show();
                                                  }
                                              }
                                              break;
                                          case 2:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      bhau3.Location = temp;
                                                      bhau3.Show();
                                                  }
                                                  else
                                                  {
                                                      bhau4.Location = temp;
                                                      bhau4.Show();
                                                  }
                                              }
                                              break;
                                          case 3:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      bhau5.Location = temp;
                                                      bhau5.Show();
                                                  }
                                                  else
                                                  {
                                                      bhau6.Location = temp;
                                                      bhau6.Show();
                                                  }
                                              }
                                              break;
                                      }
                                  }
                                  break;

                              case 6:
                                  {
                                      if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                      {
                                          bvua1.Location = temp;
                                          bvua1.Show();
                                      }
                                      else
                                      {
                                          bvua2.Location = temp;
                                          bvua2.Show();
                                      }
                                  }
                                  break;                          
                          }
                      }


                      else

                          // cap nhat man hinh quan co trang;
                      {
                          
                          // chuyen toa do code wa toa do man hinh
                          Point temp = new Point();
                          temp.X = (j * 90) + 10;
                          temp.Y = (i * 90) + 10;


                          switch (chess[i, j].Type)
                          {
                              case 1:
                                  {
                                      chot2 = chot2 + 1;
                                      switch (chot2)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot11.Location = temp;
                                                  wchot11.Show();
                                              }
                                              else
                                              {
                                                  wchot12.Location = temp;
                                                  wchot12.Show();
                                              }
                                              break;
                                          /////
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot21.Location = temp;
                                                  wchot21.Show();
                                              }
                                              else
                                              {
                                                  wchot22.Location = temp;
                                                  wchot22.Show();
                                              }

                                              break;
                                          ////
                                          case 3:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot31.Location = temp;
                                                  wchot31.Show();
                                              }
                                              else
                                              {
                                                  wchot32.Location = temp;
                                                  wchot32.Show();
                                              }
                                              break;
                                          ////
                                          case 4:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot41.Location = temp;
                                                  wchot41.Show();
                                              }
                                              else
                                              {
                                                  wchot42.Location = temp;
                                                  wchot42.Show();
                                              }

                                              break;
                                          ////
                                          case 5:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot51.Location = temp;
                                                  wchot51.Show();
                                              }
                                              else
                                              {
                                                  wchot52.Location = temp;
                                                  wchot52.Show();
                                              }

                                              break;
                                          ////
                                          case 6:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot61.Location = temp;
                                                  wchot61.Show();
                                              }
                                              else
                                              {
                                                  wchot62.Location = temp;
                                                  wchot62.Show();
                                              }

                                              break;
                                          ////
                                          case 7:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot71.Location = temp;
                                                  wchot71.Show();
                                              }
                                              else
                                              {
                                                  wchot72.Location = temp;
                                                  wchot72.Show();
                                              }

                                              break;
                                          ////
                                          case 8:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wchot81.Location = temp;
                                                  wchot81.Show();
                                              }
                                              else
                                              {
                                                  wchot82.Location = temp;
                                                  wchot82.Show();
                                              }

                                              break;
                                          ////
                                      }
                                  }
                                  break;
                              case 2:
                                  {
                                      xe2 = xe2 + 1;
                                      switch (xe2)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wxe11.Location = temp;
                                                  wxe11.Show();
                                              }
                                              else
                                              {
                                                  wxe12.Location = temp;
                                                  wxe12.Show();
                                              }
                                              break;
                                          ///
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wxe21.Location = temp;
                                                  wxe21.Show();
                                              }
                                              else
                                              {
                                                  wxe22.Location = temp;
                                                  wxe22.Show();
                                              }
                                              break;
                                      }
                                  }
                                  break;

                              //
                              case 3:
                                  {
                                      ma2 = ma2 + 1;
                                      switch (ma2)
                                      {
                                          case 1:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wma11.Location = temp;
                                                  wma11.Show();
                                              }
                                              else
                                              {
                                                  wma12.Location = temp;
                                                  wma12.Show();
                                              }
                                              break;
                                          ///
                                          case 2:
                                              if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                              {
                                                  wma21.Location = temp;
                                                  wma21.Show();
                                              }
                                              else
                                              {
                                                  wma22.Location = temp;
                                                  wma22.Show();
                                              }
                                              break;
                                      }
                                  }
                                  break;

                              case 4:
                                  {
                                      if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                      {
                                          wtuong1.Location = temp;
                                          wtuong1.Show();
                                      }
                                      else
                                      {
                                          wtuong2.Location = temp;
                                          wtuong2.Show();
                                      }
                                  }
                                  break;

                              case 5:
                                  {
                                      hau2 = hau2 + 1;
                                      switch (hau2)
                                      {
                                          case 1:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      whau1.Location = temp;
                                                      whau1.Show();
                                                  }
                                                  else
                                                  {
                                                      whau2.Location = temp;
                                                      whau2.Show();
                                                  }
                                              }
                                              break;
                                          case 2:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      whau3.Location = temp;
                                                      whau3.Show();
                                                  }
                                                  else
                                                  {
                                                      whau4.Location = temp;
                                                      whau4.Show();
                                                  }
                                              }
                                              break;
                                          case 3:
                                              {
                                                  if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                                  {
                                                      whau5.Location = temp;
                                                      whau5.Show();
                                                  }
                                                  else
                                                  {
                                                      whau6.Location = temp;
                                                      whau6.Show();
                                                  }
                                              }
                                              break;
                                      }
                                  }
                                  break;

                              case 6:
                                  {
                                      if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0))
                                      {
                                          wvua1.Location = temp;
                                          wvua1.Show();
                                      }
                                      else
                                      {
                                          wvua2.Location = temp;
                                          wvua2.Show();
                                      }
                                  }
                                  break;
                          }
                      }
                    
        
     
                       //   if (chess[i, j].Type != 0)
                       //   {
                      //       Console.Write("[");
                      //       if (chess[i, j].Type == 1)
                      //            Console.Write("Chot");
                      //        else if (chess[i, j].Type == 2)
                      //            Console.Write(" Xe ");
                       //       else if (chess[i, j].Type == 3)
                      //            Console.Write("Ngua");
                      //        else if (chess[i, j].Type == 4)
                       //           Console.Write("Tinh");
                      // //       else if (chess[i, j].Type == 5)
                       //           Console.Write("Hau ");
                      //        else if (chess[i, j].Type == 6)
                       //           Console.Write("Vua ");
                       //       Console.Write("-");
                       //       if (chess[i, j].Player == 1)
                      //             Console.Write("1]");
                     //         else Console.Write("2]");
                      //    }
                      //    else Console.Write("--------");
                       //   if (j < 7)
                      //        Console.Write ("*");

                  }
                //  if(i<7)
                  //Console.Write("\n*\n*\n");
               

            
              }
        
          }
        // hung viet lai ham move khac
          int x = 1;
          public void DanhCo()
          {
              short i = -1; short j = -1; short p = -1 ; short q = -1;
              short k = 0,t;
              if (x == 1)
              {
                  t = 1;
                  tb1.Text = "Người chơi 1 đánh cờ";
                  tb1.Show();
              }
              else
              {
                  t = 2;
                  tb1.Text = "Người chơi 2 đánh cờ";
                  tb1.Show();
              }                    
             
            // if (chon == 1)
              //if ((i == -1) && (j == -1))
              if (toadodi.X != -1)
              {
                  i = (short)toadodi.X;
                  j = (short)toadodi.Y;
                  if ((i >= 0 && i <= 7) && (j >= 0 && j <= 7) && (chess[i, j].Player == t) && (chess[i, j].Type != 0))
                  {
                      chon = 2;
                      if (toadoden.Y != -1)
                      {
                          p = (short)toadoden.X;
                          q = (short)toadoden.Y;
                          if ((((p >= 0 && p <= 7) && (q >= 0 && q <= 7)) && Check(i, j, p, q) == 1) || (i == p && j == q))
                          {
                              if (chess[p, q].Type == 6)
                                  k = chess[i, j].Player;
                              if (chess[i, j].Player == 1 && p == 7 && chess[i, j].Type == 1)
                                  chess[p, q] = new Chessman(p, q, 5, 1);
                              else if (chess[i, j].Player == 2 && p == 0 && chess[i, j].Type == 1)
                                  chess[p, q] = new Chessman(p, q, 5, 2);
                              else
                                  chess[p, q] = new Chessman(p, q, chess[i, j].Type, chess[i, j].Player);
                              chess[i, j] = new Chessman(i, j);
                              x = x * (-1);

                              if (x == 1)
                              {
                                  t = 1;
                                  tb1.Text = "Người chơi 1 đánh cờ";
                                  tb1.Show();
                              }
                              else
                              {
                                  t = 2;
                                  tb1.Text = "Người chơi 2 đánh cờ";
                                  tb1.Show();
                              }
                              // toadodi.X = -1;
                              // toadodi.Y = -1;
                              // toadoden.X = -1;
                              // toadoden.Y = -1;

                          }
                          else
                          {

                          }
                          CapNhat();
                          i = -1; j = -1; p = -1; q = -1;
                          chon = 1;
                          toadodi.X = -1;
                          toadodi.Y = -1;
                          toadoden.X = -1;
                          toadoden.Y = -1;

                      }
                  }
                  else
                  {
                      i = -1;
                      j = -1;
                      chon = 1;
                      toadodi.X = -1;
                      toadodi.Y = -1;
                      toadoden.X = -1;
                      toadoden.Y = -1;
                  }


                  // if (chon == 2)
                  //if ((chon != 1))
                  //if ((i!=-1)&&(j!=-1)&&(p==-1)&&(q==-1))
                  
              }
              /*   switch (chon)
           {
               case 1:
                   {
                       i = (short)toadodi.X;
                       j = (short)toadodi.Y;
                       if ((i >= 0 && i <= 7) && (j >= 0 && j <= 7) && (chess[i, j].Player == t) && (chess[i, j].Type != 0))
                       {
                           chon = 2;
                       }
                       else
                       {
                           i = -1;
                           j = -1;
                           chon = 1;
                       }
                   }
                   break;
               case 2:
                   {
                       p = (short)toadoden.X;
                       q = (short)toadoden.Y;
                       if ((((p >= 0 && p <= 7) && (q >= 0 && q <= 7)) && Check(i, j, p, q) == 1) || (i == p && j == q))
                       {
                           if (chess[p, q].Type == 6)
                               k = chess[i, j].Player;
                           if (chess[i, j].Player == 1 && p == 7 && chess[i, j].Type == 1)
                               chess[p, q] = new Chessman(p, q, 5, 1);
                           else if (chess[i, j].Player == 2 && p == 0 && chess[i, j].Type == 1)
                               chess[p, q] = new Chessman(p, q, 5, 2);
                           else
                               chess[p, q] = new Chessman(p, q, chess[i, j].Type, chess[i, j].Player);
                           chess[i, j] = new Chessman(i, j);
                           x = x * (-1);

                           if (x == 1)
                           {
                               t = 1;
                               tb1.Text = "1";
                               tb1.Show();
                           }
                           else
                           {
                               t = 2;
                               tb1.Text = "2";
                               tb1.Show();
                           }
                          // toadodi.X = -1;
                           //toadodi.Y = -1;
                           //toadoden.X = -1;
                           //toadoden.Y = -1;
                           chon = 1;
                       }
                       else
                       {

                       }
                       CapNhat();
                       i = -1; j = -1; p = -1; q = -1;
                         
                  
                   }
                   break;
           }
           */
              
          }

   /*     public short Move(short t)
         {
             short i, j, p, q,k=0;
             do
             {
                 i = (short)(toadodi.X);
                 j = (short)(toadodi.Y);
                // Console.Write("\nNhap vi tri quan co can di:\nx= ");
                 //i = Convert.ToInt16(Console.ReadLine());
                 //Console.Write("y= ");
                 //j = Convert.ToInt16(Console.ReadLine());
             }while(!((i>=0 && i<=7) && (j>=0 && j<=7) && (chess[i,j].Player == t)&&(chess[i,j].Type!=0)));
             do
             {
                 p = (short)(toadoden.X);
                 q = (short)(toadoden.Y);
                 //Console.Write("\nNhap vi tri quan co duoc chon can den:\nx= ");
                 //p = Convert.ToInt16(Console.ReadLine());
                 //Console.Write("y= ");
                 //q = Convert.ToInt16(Console.ReadLine());
             }while(!(((p>=0 && p<=7) && (q>=0 && q<=7)) && Check(i,j,p,q)==1) || (i==p && j==q));
             if (chess[p, q].Type == 6)
                 k = chess[i, j].Player;
             if (chess[i, j].Player == 1 && p == 7 && chess[i, j].Type == 1)
                 chess[p, q] = new Chessman(p, q, 5, 1);
             else if (chess[i, j].Player == 2 && p == 0 && chess[i, j].Type == 1)
                 chess[p, q] = new Chessman(p, q, 5, 2);
             else
                 chess[p, q] = new Chessman(p, q, chess[i, j].Type, chess[i, j].Player);
                 chess[i, j] = new Chessman(i, j);

            //cap nhat man hinh
                 CapNhat();

                 return k;

            
            
        
        
        
         }*/
         public Chessman[,] Chess
         {
             get { return chess; }
             set { chess = value; }
         }
         public short Check(short i, short j, short p, short q)
         {
             short t=0,m,n;
             if (chess[i, j].Type == 2)
             {
                 if ((i != p && j != q) || (i==p && j==q))
                     return t;
                 if (chess[i, j].Player == chess[p, q].Player)
                     return t;
                 if (i != p)
                     if (i < p)
                     {
                         for (m = (short)(i + 1); m < p; m++)
                             if (chess[m, j].Type != 0)
                                 return t;
                     }
                     else
                         for (m = (short)(i - 1); m > p; m--)
                             if (chess[m, j].Type != 0)
                                 return t;
                 if(j!=q)
                     if (j < q)
                     {
                         for (m = (short)(j + 1); m < q; m++)
                             if (chess[i, m].Type != 0)
                                 return t;
                     }
                     else
                         for (m = (short)(j - 1); m > q; m--)
                             if (chess[i, m].Type != 0)
                                 return t;
                 return (t = 1);
             }
             if (chess[i, j].Type == 3)
             {
                 if (chess[i, j].Player == chess[p, q].Player)
                     return 0;
                 if ((i == p + 2 || i == p - 2) && (j == q - 1 || j == q + 1))
                     return 1;
                 if ((j == q + 2 || j == q - 2) && (i == p - 1 || i == p + 1))
                     return 1;
                 return 0;            
             }
             if (chess[i, j].Type == 4)
             {
                 if (chess[i, j].Player == chess[p, q].Player)
                     return 0;
                 if ((i - p == j - q) || (i - p == q - j) || (p - i == j - q) || (p - i == q - j))
                 {
                     if (i > p)
                         if (j > q)
                             for (m = (short)(i - 1), n = (short)(j - 1); m > p; m--)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n--;
                             }
                         else
                             for (m = (short)(i - 1), n = (short)(j + 1); m > p; m--)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n++;
                             }
                     else
                         if (j > q)
                             for (m = (short)(i + 1), n = (short)(j - 1); m < p; m++)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n--;
                             }
                         else
                             for (m = (short)(i + 1), n = (short)(j + 1); m < p; m++)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n++;
                             }
                     return 1;
                 }
                
                 return 0;
                
             }
             if (chess[i, j].Type == 5)
             {
                 if (chess[i, j].Player == chess[p, q].Player)
                     return 0;
                 if ((i - p == j - q) || (i - p == q - j) || (p - i == j - q) || (p - i == q - j))
                 {
                     if (i > p)
                         if (j > q)
                             for (m = (short)(i - 1), n = (short)(j - 1); m > p; m--)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n--;
                             }
                         else
                             for (m = (short)(i - 1), n = (short)(j + 1); m > p; m--)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n++;
                             }
                     else
                         if (j > q)
                             for (m = (short)(i + 1), n = (short)(j - 1); m < p; m++)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n--;
                             }
                         else
                             for (m = (short)(i + 1), n = (short)(j + 1); m < p; m++)
                             {
                                 if (chess[m, n].Type != 0)
                                     return 0;
                                 n++;
                             }
                     return 1;
                 }
                 if (!(i != p && j != q))
                 {
                     if (i != p)
                         if (i < p)
                         {
                             for (m = (short)(i + 1); m < p; m++)
                                 if (chess[m, j].Type != 0)
                                     return 0;
                         }
                         else
                             for (m = (short)(i - 1); m > p; m--)
                                 if (chess[m, j].Type != 0)
                                     return 0;
                     if (j != q)
                         if (j < q)
                         {
                             for (m = (short)(j + 1); m < q; m++)
                                 if (chess[i, m].Type != 0)
                                     return 0;
                         }
                         else
                             for (m = (short)(j - 1); m > q; m--)
                                 if (chess[i, m].Type != 0)
                                     return 0;
                     return 1;
                
                 }
            
            
             }
             if (chess[i, j].Type == 6)
             {
                 if (chess[i, j].Player == chess[p, q].Player)
                     return 0;
                 if ((i - p == j - q) || (i - p == q - j) || (p - i == j - q) || (p - i == q - j))
                     if (i - p == 1 || p - i == 1)
                         return 1;
                 if (!(i != p && j != q))
                     if (i - p == 1 || p - i == 1 || j - q == 1 || q - j == 1)
                         return 1;
   
             }
             if (chess[i,j].Type == 1)
             {
                 if (chess[i, j].Player == 1)
                 {
                     if (p - i == 1 && q == j)
                         if (chess[p, q].Type == 0)
                             return 1;
                     if (p - i == 1 && (q - j == 1 || j - q == 1))
                         if (chess[p, q].Player == 2)
                             return 1;
                     if (p - i == 2 && q == j)
                         if (i == 1)
                             if (chess[p, q].Type == 0)
                                 return 1;
                     return 0;
                
                 }
                 else if (chess[i, j].Player == 2)
                 {
                     if (i - p == 1 && q == j)
                         if (chess[p, q].Type == 0)
                             return 1;
                     if (i - p == 1 && (q - j == 1 || j - q == 1))
                         if (chess[p, q].Player == 1)
                             return 1;
                     if (i - p == 2 && q == j)
                         if (i == 6)
                             if (chess[p, q].Type == 0)
                                 return 1;
                     return 0;
                
                
                 }
            
             }
             return 0;
         }
         Chessman[,] chess = new Chessman[8, 8];
                

       

          private void bvua1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bvua1.Location.X;
            temp.Y = bvua1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }
            // tb1.Show(a.ToString, "  ", b.ToString);
         

         

        private void bvua2_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = bvua2.Location.X;
            temp.Y = bvua2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();

        }

        private void bxe11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bxe11.Location.X;
            temp.Y = bxe11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bxe12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bxe12.Location.X;
            temp.Y = bxe12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bxe21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bxe21.Location.X;
            temp.Y = bxe21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void btuong2_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = btuong2.Location.X;
            temp.Y = btuong2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot11.Location.X;
            temp.Y = bchot11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bma22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bma22.Location.X;
            temp.Y = bma22.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        

        private void btuong1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = btuong1.Location.X;
            temp.Y = btuong1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bma11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bma11.Location.X;
            temp.Y = bma11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot82_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot82.Location.X;
            temp.Y = bchot82.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot71_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot71.Location.X;
            temp.Y = bchot71.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
            // lay toa do a b 
        }

        private void bchot62_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot62.Location.X;
            temp.Y = bchot62.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot51_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot51.Location.X;
            temp.Y = bchot51.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot42_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bchot42.Location.X;
            temp.Y = bchot42.Location.Y;

            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot31_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bchot31.Location.X;
            temp.Y = bchot31.Location.Y;

            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bchot22.Location.X;
            temp.Y = bchot22.Location.Y;

            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox65_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox65.Location.X;
            temp.Y = pictureBox65.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot12.Location.X;
            temp.Y = bchot12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
            
        }

        private void pictureBox17_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox17.Location.X;
            temp.Y = pictureBox17.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();

            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
           // short b = Move(1);
        }

        

       
        private void wchot11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot11.Location.X;
            temp.Y = wchot11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox42_Click(object sender, EventArgs e)
        {
            /*Point temp = new Point();
            temp.X = pictureBox65.Location.X;
            temp.Y = pictureBox65.Location.Y;
            if (chon == 1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            DanhCo();*/
            Point temp = new Point();
            temp.X = pictureBox42.Location.X;
            temp.Y = pictureBox42.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot21.Location.X;
            temp.Y = bchot21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot32_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot32.Location.X;
            temp.Y = bchot32.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot41_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot41.Location.X;
            temp.Y = bchot41.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot52_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot52.Location.X;
            temp.Y = bchot52.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot61_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot61.Location.X;
            temp.Y = bchot61.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void bchot72_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot72.Location.X;
            temp.Y = bchot72.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bchot81_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bchot81.Location.X;
            temp.Y = bchot81.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot12.Location.X;
            temp.Y = wchot12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot22.Location.X;
            temp.Y = wchot22.Location.Y;

           // if (chon == 1)
            if (toadodi.X==-1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
           // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot21.Location.X;
            temp.Y = wchot21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot32_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot32.Location.X;
            temp.Y = wchot32.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot31_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot31.Location.X;
            temp.Y = wchot31.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot42_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot42.Location.X;
            temp.Y = wchot42.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot41_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot41.Location.X;
            temp.Y = wchot41.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot51_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot51.Location.X;
            temp.Y = wchot51.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot52_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot52.Location.X;
            temp.Y = wchot52.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot61_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot61.Location.X;
            temp.Y = wchot61.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot62_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot62.Location.X;
            temp.Y = wchot62.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot71_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot71.Location.X;
            temp.Y = wchot71.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot72_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot72.Location.X;
            temp.Y = wchot72.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot81_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot81.Location.X;
            temp.Y = wchot81.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wchot82_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wchot82.Location.X;
            temp.Y = wchot82.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wxe22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wxe22.Location.X;
            temp.Y = wxe22.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wma11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wma11.Location.X;
            temp.Y = wma11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wtuong2_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wtuong2.Location.X;
            temp.Y = wtuong2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        

        private void wvua2_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wvua2.Location.X;
            temp.Y = wvua2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wtuong1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wtuong1.Location.X;
            temp.Y = wtuong1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wma22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wma22.Location.X;
            temp.Y = wma22.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wxe11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wxe11.Location.X;
            temp.Y = wxe11.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wma21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wma21.Location.X;
            temp.Y = wma21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wma12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wma12.Location.X;
            temp.Y = wma12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wxe21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wxe21.Location.X;
            temp.Y = wxe21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }

            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void wxe12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wxe12.Location.X;
            temp.Y = wxe12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

       

        private void wvua1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = wvua1.Location.X;
            temp.Y = wvua1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bxe22_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bxe22.Location.X;
            temp.Y = bxe22.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bma21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bma21.Location.X;
            temp.Y = bma21.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bma12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = bma12.Location.X;
            temp.Y = bma12.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

       

        private void pictureBox5_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox5.Location.X;
            temp.Y = pictureBox5.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox6.Location.X;
            temp.Y = pictureBox6.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox9.Location.X;
            temp.Y = pictureBox9.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox10_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox10.Location.X;
            temp.Y = pictureBox10.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox11.Location.X;
            temp.Y = pictureBox11.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox13_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox13.Location.X;
            temp.Y = pictureBox13.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox3.Location.X;
            temp.Y = pictureBox3.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox4.Location.X;
            temp.Y = pictureBox4.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox7.Location.X;
            temp.Y = pictureBox7.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox8.Location.X;
            temp.Y = pictureBox8.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox12_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox12.Location.X;
            temp.Y = pictureBox12.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox14_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox14.Location.X;
            temp.Y = pictureBox14.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox15_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox15.Location.X;
            temp.Y = pictureBox15.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox16_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox16.Location.X;
            temp.Y = pictureBox16.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox18_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox18.Location.X;
            temp.Y = pictureBox18.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox20_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox20.Location.X;
            temp.Y = pictureBox20.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox24_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox24.Location.X;
            temp.Y = pictureBox24.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox19_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox19.Location.X;
            temp.Y = pictureBox19.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox21_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox21.Location.X;
            temp.Y = pictureBox21.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox23_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox23.Location.X;
            temp.Y = pictureBox23.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox27_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox27.Location.X;
            temp.Y = pictureBox27.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }
         

        private void pictureBox22_Click(object sender, EventArgs e)
        {
             Point temp = new Point();
            temp.X = pictureBox22.Location.X;
            temp.Y = pictureBox22.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox26_Click(object sender, EventArgs e)
        {
             Point temp = new Point();
            temp.X = pictureBox26.Location.X;
            temp.Y = pictureBox26.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox28_Click(object sender, EventArgs e)
        {
             Point temp = new Point();
            temp.X = pictureBox28.Location.X;
            temp.Y = pictureBox28.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox30_Click(object sender, EventArgs e)
        {
             Point temp = new Point();
            temp.X = pictureBox30.Location.X;
            temp.Y = pictureBox30.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox25_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox25.Location.X;
            temp.Y = pictureBox25.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox29_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox29.Location.X;
            temp.Y = pictureBox29.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox31_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox31.Location.X;
            temp.Y = pictureBox31.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox32_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox32.Location.X;
            temp.Y = pictureBox32.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox33_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox33.Location.X;
            temp.Y = pictureBox33.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox34_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox34.Location.X;
            temp.Y = pictureBox34.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox38_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox38.Location.X;
            temp.Y = pictureBox38.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox46_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox46.Location.X;
            temp.Y = pictureBox46.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox36_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox36.Location.X;
            temp.Y = pictureBox36.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox40_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox40.Location.X;
            temp.Y = pictureBox40.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox44_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox44.Location.X;
            temp.Y = pictureBox44.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox52_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox52.Location.X;
            temp.Y = pictureBox52.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox50_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox50.Location.X;
            temp.Y = pictureBox50.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox54_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox54.Location.X;
            temp.Y = pictureBox54.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox58_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox58.Location.X;
            temp.Y = pictureBox58.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox48_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox48.Location.X;
            temp.Y = pictureBox48.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox56_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox56.Location.X;
            temp.Y = pictureBox56.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox60_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox60.Location.X;
            temp.Y = pictureBox60.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox62_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox62.Location.X;
            temp.Y = pictureBox62.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox35_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox35.Location.X;
            temp.Y = pictureBox35.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();

            DanhCo();
        }

        private void pictureBox37_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox37.Location.X;
            temp.Y = pictureBox37.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox41_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox41.Location.X;
            temp.Y = pictureBox41.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox49_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox49.Location.X;
            temp.Y = pictureBox49.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox39_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox39.Location.X;
            temp.Y = pictureBox39.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);
            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox43_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox43.Location.X;
            temp.Y = pictureBox43.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox47_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox47.Location.X;
            temp.Y = pictureBox47.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox55_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox55.Location.X;
            temp.Y = pictureBox55.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox45_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox45.Location.X;
            temp.Y = pictureBox45.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox53_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox53.Location.X;
            temp.Y = pictureBox53.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox57_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox57.Location.X;
            temp.Y = pictureBox57.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox61_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox61.Location.X;
            temp.Y = pictureBox61.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox51_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox51.Location.X;
            temp.Y = pictureBox51.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox59_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox59.Location.X;
            temp.Y = pictureBox59.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox63_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox63.Location.X;
            temp.Y = pictureBox63.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void pictureBox64_Click(object sender, EventArgs e)
        {
            Point temp = new Point();
            temp.X = pictureBox64.Location.X;
            temp.Y = pictureBox64.Location.Y;
            toadoden.Y = (short)((temp.X - 10) / 90);
            toadoden.X = (short)((temp.Y - 10) / 90);

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau2_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau2.Location.X;
            temp.Y = bhau2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau1_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau1.Location.X;
            temp.Y = bhau1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau4_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau4.Location.X;
            temp.Y = bhau4.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau3_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau3.Location.X;
            temp.Y = bhau3.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau5_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau5.Location.X;
            temp.Y = bhau5.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void bhau6_Click(object sender, EventArgs e)
        {
            Point temp = new Point();

            temp.X = bhau6.Location.X;
            temp.Y = bhau6.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau1_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau1.Location.X;
            temp.Y = whau1.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau2_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau2.Location.X;
            temp.Y = whau2.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau3_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau3.Location.X;
            temp.Y = whau3.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau4_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau4.Location.X;
            temp.Y = whau4.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau5_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau5.Location.X;
            temp.Y = whau5.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void whau6_Click(object sender, EventArgs e)
        {

            Point temp = new Point();
            temp.X = whau6.Location.X;
            temp.Y = whau6.Location.Y;
            // if (chon == 1)
            if (toadodi.X == -1)
            {
                toadodi.Y = (short)((temp.X - 10) / 90);
                toadodi.X = (short)((temp.Y - 10) / 90);

            }
            else
            // if (chon == 2)
            {
                toadoden.Y = (short)((temp.X - 10) / 90);
                toadoden.X = (short)((temp.Y - 10) / 90);

            }

            pb1.Location = temp;
            pb2.Location = temp;
            pb1.Show();
            pb2.Show();
            temp.Y = temp.Y + 80;
            pb4.Location = temp;
            pb4.Show();
            temp.X = temp.X + 80;
            temp.Y = temp.Y - 80;
            pb3.Location = temp;
            pb3.Show();
            DanhCo();
        }

        private void ngchoi1_Click(object sender, EventArgs e)
        {
            tb1.Text = " Người chơi 2 thắng !!";
            TaiKhoan.Update_Thang(ten2, DaTa);
            TaiKhoan.Update_Thua(ten1, DaTa);
            
            tb1.Show();
            NewGame();
            
        }

        private void ngchoi2_Click(object sender, EventArgs e)
        {
            tb1.Text = " Người chơi 1 thắng !!";
           
            TaiKhoan.Update_Thang(ten1, DaTa);
            TaiKhoan.Update_Thua(ten2, DaTa);
            tb1.Show();
            NewGame();

        }

        private void hd_TextChanged(object sender, EventArgs e)
        {          
           hd.Text = "Người chơi 1 Cờ đỏ";                       
        }

        private void hd5_TextChanged(object sender, EventArgs e)
        {
            hd5.Text = "Người chơi 2 Cờ trắng";
        }

        private void huongdan_TextChanged(object sender, EventArgs e)
        {
            huongdan.Text = "Cách chơi: ";
        }

        private void hd1_TextChanged(object sender, EventArgs e)
        {
            hd1.Text = "Chọn quân cờ cần đi";
        }

        private void hd2_TextChanged(object sender, EventArgs e)
        {
            hd2.Text = " Chọn nơi cần đến.";
        }

        private void hd3_TextChanged(object sender, EventArgs e)
        {
            hd3.Text = "Nếu quân cờ chưa được đánh.";
        }

        private void hd4_TextChanged(object sender, EventArgs e)
        {
            hd4.Text = "Chọn lại quân cờ cần đi.";
        }

       

        private void luu_Click(object sender, EventArgs e)
        {
            file_luu.Show();
            AnCo();
            file_luu.Show();
            ten_luu.Show();
            luu_file.Show();
            ten_luu.Text = "Tên Lưu :";
          
           
        }

        private void Mo_luu_Click(object sender, EventArgs e)
        {
            AnCo();
           
            mo.Show();
            file_luu.Show();
            ten_luu.Show();
        }

        private void mo_Click(object sender, EventArgs e)
        {
           
           
            file_luu.Text = file_luu.Text + ".txt";
           ChessBoard();
            short i=0, j=0;
            //doc file
            try
            {

                StreamReader Re = File.OpenText(file_luu.Text);

                string s = "";
                string st;
                for (i = 0; i < 8; i++)
                {
                    // string st;
                    st = Re.ReadLine();
                    for (j = 0; j < 8; j++)
                    {
                        //  MessageBox.Show(st[j*2].ToString());
                        chess[i, j].Type = short.Parse(st[j * 2].ToString());
                    }
                }
                for (i = 0; i < 8; i++)
                {
                    //string st;
                    st = Re.ReadLine();
                    for (j = 0; j < 8; j++)
                    {
                        //MessageBox.Show(st[j*2].ToString());
                        chess[i, j].Player = short.Parse(st[j * 2].ToString());
                    }
                }

                st = Re.ReadLine();
                if (st.Length == 1)
                    x = 1;
                else
                    x = -1;

                Re.Close();

                CapNhat();
            }
            catch (FileNotFoundException)
            {
                MessageBox.Show("Tên ván đấu bạn mở không tồn tại");
            }
            catch (FileLoadException)
            {
                MessageBox.Show("Không mở được ván đấu này!");
            }
            /*   FileInfo myfile = new FileInfo("f:/inne.txt");
              StreamWriter tex1 = myfile.CreateText();
              //tex.Write(tex.NewLine);
            
              //short i, j;
             for (i = 0; i < 8; i++)
              {
                  for (i = 0; i < 8; i++)
                  {
                      for (j = 0; j < 8; j++)
                      {
                          tex1.Write(chess[i, j].Type);
                          tex1.Write(" ");
                      }
                      tex1.WriteLine();
                  }
                  for (i = 0; i < 8; i++)
                  {
                      for (j = 0; j < 8; j++)
                      {
                          tex1.Write(chess[i, j].Player);
                          tex1.Write(" ");
                      }
                      tex1.WriteLine();
                  }
              }
              tex1.Close();
              ///
             */
            file_luu.Text = "";
            mo.Hide();
            ten_luu.Hide();
            file_luu.Hide();

            

        }

        private void luu_file_Click(object sender, EventArgs e)
        {
             
            // chuyen ten thanh file txt.
            file_luu.Text = file_luu.Text + ".txt";
            //ghi file
            FileInfo myfile = new FileInfo(file_luu.Text);
            StreamWriter tex = myfile.CreateText();
            //tex.Write(tex.NewLine);

            short i, j;
            for (i = 0; i < 8; i++)
            {
                for (j = 0; j < 8; j++)
                {
                    tex.Write(chess[i, j].Type);
                    tex.Write(" ");
                }
                tex.WriteLine();
            }
            for (i = 0; i < 8; i++)
            {
                for (j = 0; j < 8; j++)
                {
                    tex.Write(chess[i, j].Player);
                    tex.Write(" ");
                }
                tex.WriteLine();
            }
            tex.WriteLine(x);
            // tex.WriteLine(input);
            // tex.WriteLine("Day la cach doc ghi trong C#");
            //Console.WriteLine("Da ghi thanh cong!!!");
            tex.Close();
            file_luu.Text = "";
            file_luu.Hide();
            ten_luu.Hide();
            luu_file.Hide();

        
        }

        private void ten_luu_TextChanged(object sender, EventArgs e)
        {
            ten_luu.Text = "Tên Lưu :";
        }
        

        
     
      
       
       
      
           
       
        
     }
     public class Chessman
     {
         public Chessman(short a, short b)
         {
             this.x = a;
             this.y = b;
             this.type = 0;
             this.player = 0;
         }
         public Chessman(short a, short b, short p, short q)
         {
             this.x = a;
             this.y = b;
             this.type = p;
             this.player = q;
         }

         public short X
         {
             get { return x; }
             set { x = value; }
         }
         public short Y
         {
             get { return y; }
             set { y = value; }
         }
         public short Type
         {
             get { return type; }
             set { type = value; }
         }
         public short Player
         {
             get { return player; }
             set { player = value; }
         }
         short x;
         short y;
         short type;
         short player;
    
    
     }
}   

